#include <avr/io.h>

uint16_t GenerateChecksum(uint8_t *data, uint8_t count)
{
	uint16_t sum1 = 0;               /*the sums are made 16bit variables to avoid overflow during addition*/
	uint16_t sum2 = 0;
	int index;
	
	for( index = 0; index < count; ++index )
	{
		sum1 = (sum1 + data[index]) % 255;   /*add together all the 8-bit bytes of the array and divide by 255*/
		sum2 = (sum2 + sum1) % 255;          /*The new value for sum1 is added into sum2 and divided by 255*/
	}
	
	return (sum2 << 8) | sum1;   //multiply sum2 by 256 and stack the sums side by side with the simple checksum at the least significant end
}